﻿using Roton.Memory;
using Roton.ZZT;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Roton.Wrapper
{
    /// <summary>
    /// Adapts ILocation to Segment object.
    /// </summary>
    class LocationWrapper : ILocation
    {
        protected int offset;
        protected Segment segment;

        public LocationWrapper(int offset, Segment segment)
        {
            this.offset = offset;
            this.segment = segment;
        }

        public override string ToString()
        {
            return "[" + X.ToString() + "," + Y.ToString() + "]";
        }

        public ILocation Add(ILocation other)
        {
            return new LocationValue(X + other.X, Y + other.Y);
        }

        public ILocation Add(IVector vector)
        {
            return new LocationValue(X + vector.X, Y + vector.Y);
        }

        public ILocation Subtract(ILocation other)
        {
            return new LocationValue(X - other.X, Y - other.Y);
        }

        public ILocation Subtract(IVector vector)
        {
            return new LocationValue(X - vector.X, Y - vector.Y);
        }

        public int X
        {
            get
            {
                return segment.Read8(offset);
            }
            set
            {
                segment.Write8(offset, value);
            }
        }

        public int Y
        {
            get
            {
                return segment.Read8(offset + 1);
            }
            set
            {
                segment.Write8(offset + 1, value);
            }
        }
    }
}
